#include "ThreadPool.h"

bool concurrent::ThreadPool::_initialised;
concurrent::ThreadPool concurrent::ThreadPool::_instance;

concurrent::ThreadPool::ThreadPool(void)
{
}

concurrent::ThreadPool::~ThreadPool(void)
{
}

concurrent::ThreadPool* concurrent::ThreadPool::getInstance(void)
{
	return _initialised ? &_instance : 0;
}

concurrent::Thread* concurrent::ThreadPool::execute(Runnable* runnable)
{
	Thread* thread = createThread(runnable);
	thread->start();
	return thread;
}

void concurrent::ThreadPool::release(void)
{
	list<Thread*>::iterator it;
    for (it=threads.begin();it!=threads.end();it++)
    {
        delete (*it);
    }
}

concurrent::Thread* concurrent::ThreadPool::createThread(void)
{
	Thread* t = new Thread();
	threads.push_back(t);
	return t;
}

concurrent::Thread* concurrent::ThreadPool::createThread(Runnable* runnable)
{
	Thread* t = new Thread(runnable);
	//threads.push_back(t);
	return t;
}
